﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE bhp_temp_InstallApartmentType
AS
BEGIN

	DECLARE
		@GroupId		INT,
		@TabId			INT,
		@CinemaTabId	INT

	SELECT @GroupId = id FROM n_Tree WHERE name = 'TYP_APARTAMENTU' AND parent = 0

	SELECT 
		@TabId = gt.TabId 
	FROM 
		bht_GroupTabs gt
		INNER JOIN bht_GroupColumnsSplit gcs ON gt.TabId = gcs.TabId
		INNER JOIN n_Tree t ON gcs.ColumnId = t.id 
	WHERE
		t.parent = @GroupId
		AND t.name = 'lid'

	UPDATE
		bht_GroupTabs
	SET
		TabName = 'Opis apartamentu'
	WHERE
		TabId = @TabId

	INSERT INTO bht_GroupTabs (TabName, Sort)
		VALUES ('Opis filmu', 400)

	SELECT @CinemaTabId = SCOPE_IDENTITY()

	UPDATE
		bht_GroupColumnsSplit
	SET
		TabId = @CinemaTabId
	FROM
		n_Tree t
		INNER JOIN bht_GroupColumnsSplit gcs ON t.id = gcs.ColumnId
	WHERE
		t.parent = @GroupId
		AND t.name = 'kluczowa_obsada'

	UPDATE
		bht_Columns
	SET
		Sort = 305
	FROM
		n_Tree t
		INNER JOIN bht_Columns c ON t.id = c.ColumnId
	WHERE
		t.parent = @GroupId
		AND t.name = 'topfields'
		
	
	EXEC [dbo].[n_ColFAdd] @rel = @GroupId, @name = N'opis_filmu', @typ = 2, @siz1 = 4000, @siz2 = 1, @user = 900900

	INSERT INTO bht_Columns (ColumnId, DisplayName, [Description], Sort)
    SELECT
        id, N'Opis filmu', N'', 400
    FROM
        n_Tree t
    WHERE
        parent = @GroupId
        AND name = N'opis_filmu'

	INSERT INTO bht_GroupColumnsSplit (ColumnId, TabId)
		SELECT id, @CinemaTabId FROM n_Tree WHERE name = 'opis_filmu' AND parent = @GroupId

END
GO
EXEC bhp_temp_InstallApartmentType
GO
DROP PROCEDURE bhp_temp_InstallApartmentType